package com.dragon.concurrent.demo.waitnotify;

public class ProduceConsumeVersion1 {

    private int i = 0;

    private final Object LOCK = new Object();

    public void produce() {
        synchronized (LOCK) {
            System.out.println("P->" + (i++));
        }
    }

    public void consume() {
        synchronized (LOCK) {
            System.out.println("C->" + i);
        }
    }


    public static void main(String[] args) {
        ProduceConsumeVersion1 produceConsumeVersion1 = new ProduceConsumeVersion1();
        new Thread(() -> {
            while (true) {
                produceConsumeVersion1.produce();
            }
        }).start();

        new Thread(() -> {
            while (true) {
                produceConsumeVersion1.consume();
            }
        }).start();
    }

}
